import { System } from "laya-system";
import NormalBullet from "../main/Bullets/NormalBullet";
export class Gun {
    player: Laya.Sprite;
    bulletPrefab: Laya.Prefab;
    constructor(player: Laya.Sprite, bulletPrefab: Laya.Prefab) {
        this.bulletPrefab = bulletPrefab;
        this.player = player;
    }
    lastSend = 0;
    timeLimit = 300;
    Action(x: number, y: number) {
        new NormalBullet(this.bulletPrefab)
            .setAngle({ x, y })
            .shoot(this.player);
        new NormalBullet(this.bulletPrefab)
            .setAngle({ x, y })
            .changeAngle((angle) => {
                return (angle += 15);
            })
            .shoot(this.player);
        new NormalBullet(this.bulletPrefab)
            .setAngle({ x, y })
            .changeAngle((angle) => {
                return (angle -= 15);
            })
            .shoot(this.player);
    }

    handleClick(Sprite: Laya.Sprite) {
        console.log("布置点击事件");

        System.Mouse.on("pointerdown", (e) => {
            if (new Date().getTime() - this.lastSend > this.timeLimit) {
                const { x, y } = e.getCameraCenterPos!();
                return this.Action(x, y);
            }
        });
    }
}
